<script type="text/javascript">
$(function(){
	var pg = App.batch.appIndex.ui, pp = pg.params,
		brokers = Cache.batch.brokers, broker = brokers[0];
	
	var gd = pg.find('.grid').mac('grid', {
		key: 'addr',
		cols: [{
			field: 'addr', title: '批量应用实例', width: 168
		},{
			field: 'catalog', title: '所属系统', width: 168
		},{
			field: 'status', title: '状态', width: 78,
			render: function(r) {
				return Cache.base.app.inst.status[r.status];
			}
		},{
			field: 'executions', title : '任务数', width: 40,
			render: function(r) {
				var i = 0, j = 0;
				for (var k in r.instMap) {
					i++;
					j += r.instMap[k].length;
				}
				return i + '/' + j;
			}
		},{
			field: 'id', title : '操作', width: 180,
			render: function(r, tr, gd) {
				var p = $('<div></div>'), v = r.status,
					st = '<span class="a"></span>';
				if (r.status == 0) {
					$(st).click(function(){
						mac.confirm('确定要 删除 批量应用实例 ' + r.addr + ' 吗？', function(){
							$.post(App.ctx + '/app/delete.do', {
								addr: r.addr
							}, function(rs){
								var ro = mac.eval(rs);
								if (ro.success) {
									gd.load();
								} else {
									mac.alert(ro.data, ro.params);
								}
							});
						});
					}).append('删除').appendTo(p);
				} else if (r.status == 4) {
					function cb(r, s){
						App.show({
							ctx : 'batch',
							action : 'batchAppIndex',
							params : {}
						}, $.noop, pg.parent());
					}
					$(st).click(function(){
						App.show({
							ctx: 'batch',
							action: 'appMonitor',
							params: r
						}, cb, pg.parent());
					}).append('任务监控').appendTo(p);
					p.append('&nbsp;');
					$(st).click(function(){
						App.show({
							ctx: 'soagov',
							action: 'appMonitor',
							params: r
						}, cb, pg.parent());
					}).append('资源监控').appendTo(p);
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/app/list.do',
			params: {
				catalog: broker.code, broker: broker.id, pageNo: 1, pageSize: 20
			},
			autoLoad: true
		},
		pagerLength: 10
	});
	
	pg.seek('broker').mac('combo', {
		keyField: 'code',
		displayField: 'name',
		multiSelect: false,
		width: 160,
		boxWidth: 160,
		cols : [{
			field: 'name', width: 160
		}],
		data: brokers,
		onSelect: function(me, sk, sd){
			broker = sd[0];
			gd.load({ catalog: broker.code, broker: broker.id, pageNo: 1 });
		}
	}).val(broker.code);
	
	pg.seek('refresh').click(function(){
// 		var w = mac.wait('Loading');
		gd.load();
// 		w.close();
	});
	
	function adjust(){
		var p = pg.parent(), w = p.width(), h = p.height();
		pg.width(w - 64);
		gd.parent().height(h - 96);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
 <div class="navi">
	<div class="title">
		<span class="a" name="back">批量应用</span>&gt;&gt;
		<span name="title">全部应用</span>
	</div>
</div>
<div class="head">
	<span class="fl">所属系统：</span>
	<div class="combo fl" name="broker"></div>
	<span class="fl">&nbsp;&nbsp;</span>
	<button name="refresh" class="fl">手动刷新</button>
</div>
<div class="body">
	<div class="grid"></div>
</div>